import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.*;

/**
 * 演示Java2D的最基本使用
  */
class BasicSurface extends JPanel{
    private void doDrawing(Graphics g){
        Graphics2D g2d= (Graphics2D) g;
        g2d.drawString("Java2D",50,50);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        doDrawing(g);
    }
}

public class BasicEx extends JFrame {

    public BasicEx(){
        initUI();
    }

    public void initUI(){
        add(new BasicSurface());

        setTitle("Simple Java 2D example");
        setSize(300,200);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                BasicEx ex=new BasicEx();
                ex.setVisible(true);
            }
        });
    }
}
